/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.moedik.model;

import com.moedik.classes.City;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author pudy
 */
public class CityModel extends Model {
    public CityModel() {
        super();
    }

    public ArrayList<City> getAll() {
        ArrayList<City> cities = new ArrayList<City>();
        Statement stmt = null;

        try {
            stmt = con.createStatement();
            String query = "SELECT `cities`.`id` AS `id`, `cities`.`name` AS `name` FROM `cities`";
            ResultSet rs = stmt.executeQuery(query);

            while (rs.next()) {
                City city = new City(rs.getInt("id"), rs.getString("name"));
                cities.add(city);
            }
        } catch (SQLException ex) {
            Logger.getLogger(ConfigModel.class.getName()).log(Level.SEVERE, null, ex);
        }

        return cities;
    }
}
